﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using Task;

using System.Web.UI.WebControls;

namespace WebApp.Settings
{
    public partial class Tasks : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            TasksGridView.DataSource = BuildITasks.Build().GetAllTasks();

            DataControlField DeleteButtons = new ButtonField();
            (DeleteButtons as ButtonField).CommandName = "Delete";
            (DeleteButtons as ButtonField).ButtonType = ButtonType.Image;
            (DeleteButtons as ButtonField).ImageUrl = "~/images/delete.png";
            TasksGridView.Columns.Add(DeleteButtons);

            DataControlField EditButtons = new ButtonField();
            (EditButtons as ButtonField).CommandName = "Edit";
            (EditButtons as ButtonField).ButtonType = ButtonType.Image;
            (EditButtons as ButtonField).ImageUrl = "~/images/edit.gif";
            TasksGridView.Columns.Add(EditButtons);

            TasksGridView.DataBind();
            
        }
        protected void TasksGridView_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int index = Convert.ToInt32(e.CommandArgument);

                string id_task = TasksGridView.Rows[index].ToString();

                BuildITasks.Build().DeleteTask(id_task);
               
            }

            else if (e.CommandName == "Add")
            {

            }

        }

    }
}